<?php
include "../lib/DAL/CanBo.php";

class CanBoBLL{
    function __construct(){
    }
    
    function __destruct(){
    }
    
    public function getCanBoInfo($ma_cb){
        $sql = "select * from tbl_canbo where ma_cb ='".$ma_cb."'";        
        $row = mysql_fetch_array(mysql_query($sql));
       return $this->setCbo($row);
        
    }
    
    public function getHoten_Byma($ma_cb){
        $sql = "select hoten_cb,ma_hochamhocvi from tbl_canbo where ma_cb ='".$ma_cb."'";        
        $row = mysql_fetch_array(mysql_query($sql));
       return $row['ma_hochamhocvi'].".".$row['hoten_cb'];
        
    }
    
    public function getListCanBo(){
      $result = mysql_query("select * from tbl_canbo WHERE ma_cb!='0' order by ten_cb,hoten_cb");
      $arr_canbo = array();
      $i=0;
      while($row = mysql_fetch_array($result)){
        $arr_canbo[$i] =  $this->setCbo($row);
        $i++;
      }
      return $arr_canbo;
    }
    
    public function insertCanBo($canbo){
      $sql = "insert into tbl_canbo(ma_cb, hoten_cb, ten_cb, gioitinh_cb, ngaysinh_cb, email_cb, sdt_cb, cmtnd_cb, diachi_cb, madm_tg, madm_dantoc, madm_cd, madm_plcb)
            values('".$canbo->getma_cb()."','".$canbo->gethoten_cb()."','".$canbo->getten_cb()."','".$canbo->getgioitinh_cb()."','".$canbo->getngaysinh_cb()."','".
            $canbo->getemail_cb()."','".$canbo->getsdt_cb()."','".$canbo->getcmtnd_cb()."','".$canbo->getdiachi_cb()."','". $canbo->getmadm_tg()."','".$canbo->getmadm_dantoc().
            "','".$canbo->getmadm_cd()."','" .$canbo->getmadm_plcb().");";  
      $result = mysql_query($sql) or die (mysql_error());
      return $result;
    }
    
    public function updateCanBo($canbo){
        $sql ="UPDATE tbl_canbo SET           
            hoten_cb = '".$canbo->gethoten_cb()."' 
            ,ten_cb = '".$canbo->getten_cb()."' 
            ,gioitinh_cb = '".$canbo->getgioitinh_cb()."'
            ,ngaysinh_cb = '".$canbo->getngaysinh_cb()."'
            ,email_cb = '".$canbo->getemail_cb()."'
            ,sdt_cb = '".$canbo->getsdt_cb()."' 
            ,cmtnd_cb = '".$canbo->getcmtnd_cb()."'
            ,diachi_cb = '".$canbo->getdiachi_cb()."' 
            ,madm_tg = '".$canbo->getmadm_tg()."' 
            ,madm_dantoc = '".$canbo->getmadm_dantoc()."' 
            ,madm_cd = '".$canbo->getmadm_cd()."' 
            ,madm_plcb = '".$canbo->getmadm_plcb()."'
            WHERE ma_cb = '".$canbo->getma_cb()."'";
        $result = mysql_query($sql) or die (mysql_error());
        return $result;
    }
    
    public function deleteCanBo($ma_cb){
        $sql="delete from tbl_canbo where ma_cb = '".$ma_cb."';";
        $result = mysql_query($sql) or die (mysql_error());
        return $result;
    }
    function setCbo($row){
        $canbo = new CanBo();
        $canbo->setCanBo($row['ma_cb'],$row['hoten_cb'],$row['ten_cb'],$row['cmtnd_cb'],$row['diachi_cb'],
        $row['email_cb'],$row['gioitinh_cb'],$row['madm_cd'],$row['madm_dantoc'],$row['madm_plcb'],$row['madm_tg'],$row['ngaysinh_cb'],
        $row['sdt_cb'],$row['sotaikhoan'],$row['chuyennganh'],$row['ma_hochamhocvi']);
        return $canbo;
         
    }
}

?>